Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] shallow: x.find() should not change state of x #2061

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sstern6
Copy link
Contributor

@sstern6 sstern6 commented Mar 19, 2019

Fixes #1916.

@ljharb ljharb changed the title Issue1916 [Fix] shallow: x.find() should not change state of x Mar 20, 2019
Copy link
Member

@ljharb ljharb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've rebased this.

I suspect we'll need to add shouldComponentUpdate to all the adapters.

@@ -1785,6 +1785,7 @@ describe('shallow', () => {
const wrapper = shallow(<MyComponent />, { disableLifecycleMethods: true });
expect(wrapper.find(Table).length).to.equal(0);
wrapper.instance().componentDidMount();
wrapper.update();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the need for this addition concerns me; perhaps that's OK because most people won't be manually calling a lifecycle method, but this makes it seem like it might be a breaking change :-/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb any idea or prediction on when this could be included in an official release? 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

finishing this up today

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i dont think we need this if we return true per your comment here: #2061 (comment). Checking though

@sstern6
Copy link
Contributor Author

sstern6 commented Apr 10, 2019

re > I suspect we'll need to add shouldComponentUpdate to all the adapters.

If we have the conditional to check if the shouldUpdateComponent is present why would we need to include it in all adapters?

Edit: some tests are failing, going to look into that as well, pushed some changes per your comments.

@@ -1785,6 +1785,7 @@ describe('shallow', () => {
const wrapper = shallow(<MyComponent />, { disableLifecycleMethods: true });
expect(wrapper.find(Table).length).to.equal(0);
wrapper.instance().componentDidMount();

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ljharb was able to remove the wrapper.update() by returning true in the adapter function.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still seems to be failing.

if (this[ROOT][WRAPPING_COMPONENT]) {
this[ROOT][WRAPPING_COMPONENT].unmount();
this[ROOT][WRAPPING_COMPONENT].update();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Curious why these were added?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to make tests pass; they were failing.

@ljharb
Copy link
Member

ljharb commented Apr 10, 2019

why would we need to include it in all adapters?

@sstern6 because the issue this fixes should be fixed for all versions of react, not just react 16.

@ljharb ljharb force-pushed the master branch 3 times, most recently from 40cc703 to 0a17404 Compare April 12, 2019 23:05
@plemasantos
Copy link

Hey guys!

Any news on this PR?

@lmvco
Copy link

lmvco commented Jun 6, 2019

Hi guys,

I am also waiting for this PR. Is someone looking into this?

@heldergoncalves92
Copy link

Do you have plans to release it? It is an important fix that I'm waiting for.

@ljharb
Copy link
Member

ljharb commented Jun 6, 2019

@sstern6 ping for an update?

@sstern6
Copy link
Contributor Author

sstern6 commented Jun 24, 2019

So sorry, didnt get pinged on my email. Yes I will prioritize this week.

I sincerely apologize, a lot of personal things going on right now has been hard to see this through.

If someone else would like to take it please be my guest. If not, this will be prioritized this week

@munerf
Copy link

munerf commented Jun 26, 2019

I'm also interested in this fix

@munerf
Copy link

munerf commented Jul 5, 2019

hi @sstern6, were you able to work on this? I need this, how can I help?

@plemasantos
Copy link

Hey again!

Sorry for pinging constantly, but are there any news?

@codecov
Copy link

codecov bot commented Dec 21, 2020

Codecov Report

Merging #2061 (9ab718c) into master (0e39e1f) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2061      +/-   ##
==========================================
+ Coverage   96.12%   96.13%   +0.01%     
==========================================
  Files          49       49              
  Lines        4004     4015      +11     
  Branches     1123     1127       +4     
==========================================
+ Hits         3849     3860      +11     
  Misses        155      155              
Impacted Files Coverage Δ
...enzyme-adapter-react-16/src/ReactSixteenAdapter.js 95.38% <100.00%> (+0.06%) ⬆️
packages/enzyme/src/ShallowWrapper.js 99.06% <100.00%> (+<0.01%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0e39e1f...9ab718c. Read the comment docs.

@ljharb ljharb force-pushed the master branch 4 times, most recently from 2227326 to 0d5ead7 Compare December 21, 2020 07:46
@ljharb ljharb force-pushed the master branch 3 times, most recently from 43eb75e to 39e6b1f Compare November 3, 2022 21:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

another .find() will cause the previous .find() not able to get .parent()
6 participants